#-------------------------------[知乎：叶枝黎曼]-------------------------
import heapq
def dijkstra(start):
    queue = []
    heapq.heappush(queue,(0,start))
    dis = [float('inf')]*(n + 1)
    vis = [False]*(n + 1)
    dis[start] = 0

    while queue:
        sam = heapq.heappop(queue)
        curDis = sam[0]
        curNode = sam[1]
        vis[curNode] = True
        if curNode not in link.keys():
            continue
        for node in link[curNode].keys():
            if vis[node] == False:
                if curDis + link[curNode][node] < dis[node]:
                    dis[node] = curDis + link[curNode][node]
                    heapq.heappush(queue,(dis[node],node))
    return dis

def Lin(a,b,c):
    if a not in link.keys():
        link[a] = {b:c}
    else:
        if b not in link[a].keys():
            link[a].update({b:c})
        else:
            link[a][b] = min(link[a][b],c)

n,m,s,e = map(int,input().split())
link = {}
for i in range(m):
    a,b,c = map(int,input().split())
    Lin(a,b,c)
    Lin(b,a,c)

dis = dijkstra(s)
print(dis[e])
